package helixoide.users;
//the user class is used to access users info and abilities
//user class needs to use the channel.java stuff now REMEMBER IT
import helixoide.irc.serverType.*;
import java.util.ArrayList;
public class User 
{
	private unreal32 server;
	private String userName, nickName, hostName, UUID, channel, realName, deviceUUID;
	boolean Object;
	ArrayList<String> channels;
	//the arraylist will be used to determine if a channel we are asked to speak in is valid
	private boolean lastDevicePing;
	public User(String Username, String Nickname, String hostName, String uuid, String Channel, String realname, unreal32 proto, boolean object, String dUUID)
	{
		this.userName = Username;
		this.nickName = Nickname;
		this.hostName = hostName;
		this.deviceUUID = dUUID;
		this.UUID = uuid;
		this.channels = new ArrayList<String>();
		this.realName = realname;
		server = proto;
		String time = String.valueOf(System.currentTimeMillis() / 1000);
		//we have all our info make a user
		this.Object = object;
		server.generalOut("NICK " + this.nickName + " 2 " + time + " " + this.userName +  " " + this.hostName + " " + this.hostName + " 4 :" + this.realName);
		if(object==false)
		{
			this.join(Channel);//this will eventually be loaded from the arraylist
		}
		//this section also needs to be made more dynamic: load it from the config
		lastDevicePing = false;
	}
	public String getDeviceUUID()
	{
		return this.deviceUUID;
	}
	public boolean isObject()
	{
		return this.Object;
	}
	public int findChannel(String channel)
	{
		String[] theChannels = new String[this.channels.size()];
		this.channels.toArray(theChannels);
		int found = -1;
		for(int i = 0;i<theChannels.length;i++)
		{
			if(theChannels[i]!=null && theChannels[i].trim().equals(channel.trim()))
			{
				found = i;
			}
			
		}
		return found;
	}
	public void addToChannelList(String channel)
	{
		this.channels.add(channel);
	}
	public int numberOfChannels()
	{
		return channels.size();//just gets how many channels we are in
	}
	public void privmsg(String nick, String msg)//privmsg() does exactly the same thing as say, except i put it in a seperate method inorder to keep user privmsg's seperated
	{
		server.generalOut(":" + this.getNick() + " NOTICE " + nick + " " + msg);
	}
	public void say(String c, String msg)
	{
		server.generalOut(":" + this.getNick() + " PRIVMSG " + c + " " + msg);
		// ACTION needs to be implemented
	}
	public String getRealName()
	{
		return this.realName;
	}
	public void join(String channel)
	{
		//used to join a channel, usually only 1
		System.out.println(this.findChannel(channel));
		if(this.findChannel(channel)==-1)
		{
			channels.add(channel);
			server.generalOut(":" + this.nickName + " JOIN " + channel);
		}
	}
	public void quit(String reason)
	{
		//quit from the server
		server.generalOut(":" + this.nickName + " QUIT " + reason);
	}
	public void part(String channel, String reason)
	{
		server.generalOut(":" + this.getNick() + " PART " + reason);
	}
	public void setLastDevicePing(boolean status)
	{
		this.lastDevicePing = status;
	}
	public boolean getLastDevicePing()
	{
		return this.lastDevicePing;
	}
	public String getNick()
	{
		return this.nickName;
	}
	public String getChannel()
	{
		return this.channel;
	}
	
	//No Idea what to do with this shit work on it later
	public String[] generateWhoisInfo(String requester)
	{
		/*
		 * @todo this entire thing needs to be revamped, there is something causing it to fail
		 * So this will have to wait for version 2
		 * @todo need to make it dynamicly loaded from config
		 */
		String[] toReturn = new String[9];
		toReturn[0] = ":slirc.test.helixoide.com 311 " + requester + " " + this.userName + " " + this.hostName + " * :" + this.userName;
		toReturn[1] = ":slirc.test.helixoide.com 307 " + requester + " " + this.userName + " :is a registered nick";
		toReturn[2] = ":slirc.test.helixoide.com 319 " + requester + " " + this.userName + " :" + this.channel;
		toReturn[3] = ":slirc.test.helixoide.com 312 " + requester + " " + this.userName + " slirc.test.helixoide.com :SLIRC";
		toReturn[4] = ":slirc.test.helixoide.com 313 " + requester + " " + this.userName + " :is a Bot on DarkDNA";
		toReturn[5] = ":slirc.test.helixoide.com 318 " + requester + " " + this.userName + " :End of /WHOIS list.";
		return toReturn;
		//sigh more dynamic stuff needs to be put in here
		//mainly the server and all that other fun stuff
		//also remember to change the number values after that first string they are wrong after
		//the first one
	}
	public String toString()
	{
		return userName + "|" + nickName + "|" + hostName + "|" + UUID + "|" + channel;
	}

}
